// pages/activity/detail.js

import api from '../../utils/api';
import message from '../../utils/message'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        activity_id:null,
        has_load:false,

        activity:{
           
        },
        shareInfo:null,
        packet_info:{
            title:'邀请你领取10元优惠券',
            username:'风云f35',
            money:12.00,
            packet_id: '1shhdhfhhhshhs' ,   //红包id
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        var str_options = JSON.stringify(options);
        //message.success( str_options );



        if(options.id){
            this.setData({
                activity_id: options.id
            })
            this.getActivityDetail();
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

       

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {


        var me = this;
        console.log( me.data.shareInfo );


        if( this.data.shareInfo!=null){
            var shareInfo = this.data.shareInfo;
            return shareInfo;
        }else{

            return {
                title:'邀请好友，获得10元优惠券',
                imageUrl:'/images/default-avatar.jpg',
                query:'action=invite&friend=10'
            }
        }

    },
    doShare:function(){
        wx.shareAppMessage({
          imageUrl: '/images/default-avatar.jpg',
          title:'邀请好友去注册得优惠',
          query:'action=112'
        })
    },
    
    createImage:function(){
        //生成活动二维码，方便用户打印与分享给好友
    },


    getAuth:function(){
        wx.getSetting({
          //withSubscriptions: true,
          success:function( res ){

            console.log(res);

            var str = JSON.stringify(res);
            message.success(str);
            return ;
            if(!res.authSetting['scope.writePhotosAlbum']){
                wx.authorize({
                  scope: 'scope.writePhotosAlbum',
                  success:function(){
                      message.success("用户已授权访问图片")
                  },
                  error:function(){
                      message.error("禁止访问用具相册");
                  }
                })
            }

          }
        })
    },
    getActivityDetail:function(){
        //加载活动详情

        var me = this;
        message.show_loading();
        var params = {} ;
        params.activity_id = this.data.activity_id;
        api.getActivityDetail(  params , function(response){
            message.hide_loading();
            console.log(response);

            if(response.status==1){

                console.log(response.data);
                me.setData({
                    activity_detail:response.data,
                    has_load:true
                })
            }
        })
    },
    getActivityContent:function(){
        var me = this;

        api.getActivityContent( {} , function(response){

            console.log(response);

            if(response.status==1){

                message.action_success("提示" , response.message , "去登陆" , function( response ){
                    wx.navigateTo({
                      url: '/pages/login/login'
                    })
                })

                

            }else{
                message.alert("提示" , response.message , "去登陆" , function( response ){
                    wx.navigateTo({
                      url: '/pages/login/login'
                    })
                })
            }
        })
    },
    closeDialog:function(){
        //关闭 弹出框
    }
})